// 根据角色动态生成路由
import { MockMethod } from "vite-plugin-mock";

// http://mockjs.com/examples.html#Object
const systemRouter = {
  path: "/system",
  name: "system",
  redirect: "/system/user",
  meta: {
    icon: "el-icon-setting",
    title: "message.hssysManagement",
    showLink: true,
    savedPosition: true,
    rank: 6
  },
  children: [
    {
      path: "/system/user",
      name: "user",
      meta: {
        title: "message.hsBaseinfo",
        showLink: true,
        savedPosition: true
      }
    },
    {
      path: "/system/dict",
      name: "dict",
      meta: {
        title: "message.hsDict",
        showLink: true,
        savedPosition: true
      }
    }
  ]
};

const testRouter = [
  {
    id: 8,
    menuCode: "work",
    menuName: "工作台",
    menuUrl: "",
    menuPath: "/work",
    parentId: 0,
    icon: "el-icon-message-solid",
    menuOrder: 2,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 9,
        menuCode: "workDashboard",
        menuName: "工作台",
        menuUrl: "",
        menuPath: "/work/dashboard",
        parentId: 8,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 10,
        menuCode: "workApproval",
        menuName: "审批中心",
        menuUrl: "",
        menuPath: "/work/approval",
        parentId: 8,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      }
    ]
  },
  {
    id: 11,
    menuCode: "process",
    menuName: "进度管理",
    menuUrl: "",
    menuPath: "/process",
    parentId: 0,
    icon: "el-icon-news",
    menuOrder: 3,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 12,
        menuCode: "processMain",
        menuName: "主计划管理",
        menuUrl: "",
        menuPath: "/process/main",
        parentId: 11,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 13,
        menuCode: "processMainDetail",
        menuName: "主计划详情",
        menuUrl: "",
        menuPath: "/process/main/detail",
        parentId: 11,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "N",
        resourceList: null,
        children: []
      }
    ]
  },
  {
    id: 12,
    menuCode: "change",
    menuName: "变更管理",
    menuUrl: "",
    menuPath: "/change",
    parentId: 0,
    icon: "el-icon-news",
    menuOrder: 3,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 14,
        menuCode: "changeManage",
        menuName: "变更管理",
        menuUrl: "",
        menuPath: "/change/manage",
        parentId: 11,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 15,
        menuCode: "changeManageDetail",
        menuName: "主计划详情",
        menuUrl: "",
        menuPath: "/change/manage/detail",
        parentId: 11,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "N",
        resourceList: null,
        children: []
      }
    ]
  },
  {
    id: 18,
    menuCode: "document",
    menuName: "文档管理",
    menuUrl: "",
    menuPath: "/document",
    parentId: 0,
    icon: "el-icon-news",
    menuOrder: 3,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 19,
        menuCode: "documentManage",
        menuName: "文档管理",
        menuUrl: "",
        menuPath: "/document/manage",
        parentId: 11,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 20,
        menuCode: "documentManageDetail",
        menuName: "文档管理详情",
        menuUrl: "",
        menuPath: "/document/manage/detail",
        parentId: 11,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "N",
        resourceList: null,
        children: []
      }
    ]
  },
  {
    id: 14,
    menuCode: "project",
    menuName: "项目管理",
    menuUrl: "",
    menuPath: "/project",
    parentId: 0,
    icon: "el-icon-menu",
    menuOrder: 4,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 15,
        menuCode: "projectManage",
        menuName: "项目管理",
        menuUrl: "",
        menuPath: "/project/manage",
        parentId: 14,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 16,
        menuCode: "projectKanban",
        menuName: "项目看板",
        menuUrl: "",
        menuPath: "/project/kanban",
        parentId: 14,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 17,
        menuCode: "projectManageDetail",
        menuName: "项目详情",
        menuUrl: "",
        menuPath: "/project/manage/detail",
        parentId: 14,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "N",
        resourceList: null,
        children: []
      }
    ]
  },
  {
    id: 18,
    menuCode: "acceptance",
    menuName: "验收管理",
    menuUrl: "",
    menuPath: "/acceptance",
    parentId: 0,
    icon: "el-icon-s-help",
    menuOrder: 5,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 19,
        menuCode: "acceptanceArrival",
        menuName: "到货验收",
        menuUrl: "",
        menuPath: "/acceptance/arrival",
        parentId: 18,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 20,
        menuCode: "acceptanceConcealed",
        menuName: "隐蔽验收",
        menuUrl: "",
        menuPath: "/acceptance/concealed",
        parentId: 18,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 21,
        menuCode: "acceptanceMaterial",
        menuName: "开工验收",
        menuUrl: "",
        menuPath: "/acceptance/material",
        parentId: 18,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 22,
        menuCode: "acceptanceCompleted",
        menuName: "土建竣工验收",
        menuUrl: "",
        menuPath: "/acceptance/completed",
        parentId: 18,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 23,
        menuCode: "acceptanceArrivalDetail",
        menuName: "到货验收详情",
        menuUrl: "",
        menuPath: "/acceptance/arrival/detail",
        parentId: 18,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "N",
        resourceList: null,
        children: []
      }
    ]
  },
  {
    id: 24,
    menuCode: "system",
    menuName: "系统管理",
    menuUrl: "",
    menuPath: "/system",
    parentId: 0,
    icon: "el-icon-folder",
    menuOrder: 6,
    isLeaf: "",
    isDisplay: "Y",
    resourceList: null,
    children: [
      {
        id: 25,
        menuCode: "systemRole",
        menuName: "角色管理",
        menuUrl: "",
        menuPath: "/system/role",
        parentId: 24,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 26,
        menuCode: "systemMenu",
        menuName: "菜单管理",
        menuUrl: "",
        menuPath: "/system/menu",
        parentId: 24,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 27,
        menuCode: "systemManage",
        menuName: "用户管理",
        menuUrl: "",
        menuPath: "/system/manage",
        parentId: 24,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      },
      {
        id: 28,
        menuCode: "systemOrganization",
        menuName: "组织管理",
        menuUrl: "",
        menuPath: "/system/organization",
        parentId: 24,
        icon: "",
        menuOrder: 1,
        isLeaf: "",
        isDisplay: "Y",
        resourceList: null,
        children: []
      }
    ]
  }
];
// const bussinessRouter = {
//   path: "/bussiness",
//   name: "bussiness",
//   redirect: "/bussiness/index",
//   meta: {
//     icon: "el-icon-folder",
//     title: "message.bussinessManagement",
//     showLink: true,
//     savedPosition: true,
//     rank: 6
//   },
//   children: [
//     {
//       path: "/bussiness/index",
//       name: "index",
//       meta: {
//         title: "message.bussinessManagement",
//         showLink: true,
//         savedPosition: true
//       }
//     },
//     {
//       path: "/bussiness/edit",
//       name: "edit",
//       meta: {
//         title: "message.bussinessManagement",
//         showLink: false,
//         savedPosition: false
//       }
//     },
//     {
//       path: "/bussiness/contract",
//       name: "contract",
//       meta: {
//         title: "message.contractManagement",
//         showLink: true,
//         savedPosition: true
//       }
//     }
//   ]
// };

const permissionRouter = {
  path: "/permission",
  name: "permission",
  redirect: "/permission/page",
  meta: {
    title: "message.permission",
    icon: "el-icon-lollipop",
    showLink: true,
    savedPosition: true,
    rank: 3
  },
  children: [
    {
      path: "/permission/page",
      name: "permissionPage",
      meta: {
        title: "message.permissionPage",
        showLink: true,
        savedPosition: true
      }
    },
    {
      path: "/permission/button",
      name: "permissionButton",
      meta: {
        title: "message.permissionButton",
        showLink: true,
        savedPosition: true,
        authority: []
      }
    }
  ]
};

// 添加不同按钮权限到/permission/button页面中
function setDifAuthority(authority, routes) {
  routes.children[1].meta.authority = [authority];
  return routes;
}

export default [
  {
    url: "/getAsyncRoutes",
    method: "get",
    response: () => {
      // if (query.name === "admin") {
      return {
        code: 200,
        data:
          // systemRouter,
          testRouter
        // bussinessRouter,
        // setDifAuthority("v-admin", permissionRouter)
      };
      // } else {
      //   return {
      //     code: 0,
      //     // info: [setDifAuthority("v-test", permissionRouter)]
      //     info: []
      //   };
      // }
    }
  }
] as MockMethod[];
